<template>
  <div>
    <el-table :data="structures" border>
      <el-table-column prop="field" label="字段名称" width="150px" />
      <el-table-column prop="label" label="表头名称" width="200px">
        <template #default="scope">
          <el-input v-model="scope.row.label" />
        </template>
      </el-table-column>

      <el-table-column prop="list" label="显示">
        <template #default="scope">
          <el-switch v-model="scope.row.list" inline-prompt :active-text="$t('system.yes')" :inactive-text="$t('system.no')" width="45px" />
        </template>
      </el-table-column>

      <el-table-column prop="search" label="查询">
        <template #default="scope">
          <el-switch v-model="scope.row.search" inline-prompt :active-text="$t('system.yes')" :inactive-text="$t('system.no')" width="45px" />
        </template>
      </el-table-column>

      <el-table-column prop="label" label="查询组件" width="250px">
        <template #default="scope">
          <el-select v-model="scope.row.form_component" class="w-full" filterable>
            <el-option v-for="component in formComponents" :key="component" :label="component" :value="component" />
          </el-select>
        </template>
      </el-table-column>

      <el-table-column prop="search_op" label="查询操作符" width="250px">
        <template #default="scope">
          <el-select v-model="scope.row.search_op" :placeholder="$t('generate.schema.structure.search_op.placeholder')" class="w-full">
            <el-option v-for="op in operates" :key="op" :label="op" :value="op" />
          </el-select>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script lang="ts" setup>
import { computed, watch, ref } from 'vue'
import { useGenerateStore } from './store'
import { Delete } from '@element-plus/icons-vue'

const generateStore = useGenerateStore()
console.log('子组件的值', generateStore.getStructures)

const structures = computed(() => {
  return generateStore.getStructures
})

console.log(structures)

const deleteField = (field: string) => {
  generateStore.filterStructures(field)
}

const props = defineProps({
  customcolumn: Array,
})
let flag = ref(true)
watch(
  () => structures,
  (newValue, oldValue) => {
    // 处理逻辑
    console.log('structures值发生变化:', newValue, oldValue)
    if (flag.value) {
      structures.value.forEach((obj, index) => {
        obj.label = obj.field
      })
      flag.value = false
    }
  },
  {  deep: true },
)

// const operates: string[] = ['=', '!=', '>', '>=', '<', '<=', 'like', 'RLike', 'LLike', 'in']
const operates: string[] = ['=', '!=', '>', '>=', '<', '<=', 'like']

const validates: string[] = [
  'required',
  'integer',
  'numeric',
  'string',
  'timezone',
  'url',
  'uuid',
  'date',
  'alpha',
  'alpha_dash',
  'alpha_num',
  'boolean',
  'email',
  'image',
  'file',
  'ip',
  'ipv4',
  'ipv6',
  'mac_address',
  'json',
  'nullable',
  'present',
  'prohibited',
]

// const formComponents: string[] = ['cascader', 'date', 'datetime', 'input', 'input-number', 'radio', 'rate', 'select', 'tree', 'tree-select']
const formComponents: string[] = ['input']
</script>
